<?php

namespace app\api\controller;

use app\api\model\Order as OrderModel;
use app\common\library\Sfkuaidi;
use app\common\model\OrderGoods;
use app\common\model\Setting;
use app\common\model\Setting as SettingModel;
use think\Log;

/**
 * 测试
 * Class Test
 * @package app\api
 */
class Test extends Controller
{

    public function demo()
    {
        $smsConfig = SettingModel::getItem('sms', 10001);
        return $this->renderSuccess($smsConfig);
    }

    public function createSf()
    {
        $params = [
            'outOrderNo' => '2022080555505252', //订单号，不能重复
            'senderContact' => '食之有味', //寄件人姓名
            'senderTel' => '085186608499', //寄件人联系⽅方式
            'senderAddress' => '贵州省贵阳市', //寄件人详细地址若省市区不填，则传入完整寄件地址

            'recipientContact' => '测试收货人', // 收件人姓名
            'recipientTel' => '133083643617', //收件人联系⽅方式,
            'recipientAddress' => '贵州省都匀市荔波县小七孔东门',// 收件⼈详细地址若省市区不填，则传入完整寄件地址
        ];
        $res_arr = Sfkuaidi::create($params);

        return $this->renderSuccess($res_arr);
    }

    public function cancelSf()
    {
        $outOrderNo = '2022082252100549'; //订单号，不能重复
        $res_arr = Sfkuaidi::cancel($outOrderNo);

        return $this->renderSuccess($res_arr);
    }

    public function querySf()
    {
        $outOrderNo = '2022081052101579'; //订单号，不能重复
        $mailNo     = 'SF1690412179679';

        $res_arr = Sfkuaidi::queryRoute($outOrderNo, $mailNo);

        return $this->renderSuccess($res_arr);
    }

    /**
     * 收货
     * @param int $order_id 订单号
     * @param int $user_id  用户id
     * @return array
     */
    public function receipt($order_id, $user_id)
    {
        $model = OrderModel::getUserOrderDetail((int)$order_id, (int)$user_id);

        if ($model->receipt()) {
            return $this->renderSuccess();
        }
        return $this->renderError($model->getError());
    }

}
